package kit.edu.lego.gruppe3.levels.bridge;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import lejos.nxt.LCD;
import lejos.nxt.LightSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.Behavior;

/**
 * Rotates the robot to the left when the light sensor tells him he reached the edge of the bridge
 * @author Lac
 *
 */
public class BridgeEdgeEvader implements Behavior
{
	
	private LightSensor lightS = ComponentsRepository.getInstance().getLightSensor();

	

	@Override
	public void action()
	{
		LCD.drawString("B: Edge", 0, 1);
	


		DifferentialPilot robot = ComponentsRepository.getInstance().getRobotPilot();
		robot.setRotateSpeed(90);
		robot.setTravelSpeed(5);
		robot.travel(-1.1f);
		robot.rotate(35);

	}

	@Override
	public void suppress()
	{

	}

	@Override
	public boolean takeControl()
	{
		LCD.drawString(lightS.getLightValue()+"", 0,2);
		return LevelSelector.getInstance().isBridge() &&
			lightS.getLightValue() < ComponentsRepository.BRIDGE_LIGHT_TRASHOLD;
	}

}
